import {Money} from "@/api/sys/dnf/money/types";
import {useGetOptions} from "@/utils/use/use-get-options";
import {DictType} from "@/utils/enum-type";
import {getMoneyListApi, signMoneyApi} from "@/api/sys/dnf/money";
import {signApi} from "@/api/sys/dnf/sign";
import {sleep} from "@/utils/common-fn";

export const useMoneyStore = defineStore('money', () => {
    // 货币数据
    const data: Ref<Money[]> = ref([])
    let options = useGetOptions(DictType.DnfPriceType)
    // options
    const dnfPriceTypeOptions = computed(() => options.value[0])

    // 展示签到
    const show = ref(true)

    async function sign() {
        const bool = await signApi()
        if (bool) {
            // 充值7W点券
            await signMoneyApi()
            ElMessage.success('今天也是充满七万的一天,请查收.')
            await sleep(1000)
            await getList()
        } else {
            ElMessage.warning('客官,七万已经领过了,请明日再来')
        }
        show.value = false
    }

    async function getList() {
        data.value = await getMoneyListApi()
        options = useGetOptions(DictType.DnfPriceType)
    }


    return {data, dnfPriceTypeOptions, show, sign, getList}
})
